﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace BarManager.UI.Web.HtmlHelpers
{
    public static class DateHelper
    {
        public static MvcHtmlString DatePicker(this HtmlHelper html, DateTime? value, string id)
        {
            TagBuilder divTag = new TagBuilder("div");
            divTag.AddCssClass("date input-append");            

            TagBuilder spanTag = new TagBuilder("span");
            spanTag.AddCssClass("add-on");

            TagBuilder iTag = new TagBuilder("i");
            iTag.MergeAttribute("data-time-icon", "icon-time");
            iTag.MergeAttribute("data-date-icon", "icon-calendar");           

            spanTag.InnerHtml += iTag.ToString();
            if (value.HasValue)
                divTag.InnerHtml += "<input data-format=\"dd/mm/yyyy\" placeholder=\"dd/mm/aaaa\" type=\"text\"  id=\"" + id + "\"  class=\"input-small\" value=\"" + value.Value.ToString("dd/MM/yyyy") + "\">";
            else
                divTag.InnerHtml += "<input data-format=\"dd/mm/yyyy\" placeholder=\"dd/mm/aaaa\" type=\"text\"  id=\"" + id + "\"  class=\"input-small\" value=\"\">";
            divTag.InnerHtml += spanTag.ToString();

            return MvcHtmlString.Create(divTag.ToString());
        }
    }
}